FragmentStatePagerAdapter

Deprecated

Switch to androidx.viewpager2.widget.ViewPager2 and use androidx.viewpager2.adapter.FragmentStateAdapter instead.

Implementation of PagerAdapter that uses a Fragment to manage each page. This class also handles saving and restoring of fragment's state.

This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.

When using FragmentPagerAdapter the host ViewPager must have a valid ID set.

Subclasses only need to implement getItem and getCount to have a working adapter.

Here is an example implementation of a pager containing fragments of lists: {@sample samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentStatePagerSupport.java * complete}

The R.layout.fragment_pager resource of the top-level fragment is: {@sample samples/Support4Demos/src/main/res/layout/fragment_pager.xml * complete}

The R.layout.fragment_pager_list resource containing each individual fragment's layout is: {@sample samples/Support4Demos/src/main/res/layout/fragment_pager_list.xml * complete}

Constructors

Link copied to clipboard
constructor(@NonNull fm: FragmentManager)
Constructor for FragmentStatePagerAdapter that sets the fragment manager for the adapter.
constructor(@NonNull fm: FragmentManager, behavior: Int)
Constructor for FragmentStatePagerAdapter.

Properties

Link copied to clipboard
Indicates that only the current fragment will be in the RESUMED state.
Link copied to clipboard
Indicates that setUserVisibleHint will be called when the current fragment changes.

Functions

Link copied to clipboard
open fun destroyItem(@NonNull container: ViewGroup, position: Int, @NonNull object: Any)
Link copied to clipboard
open fun finishUpdate(@NonNull container: ViewGroup)
Link copied to clipboard
abstract fun getItem(position: Int): Fragment
Return the Fragment associated with a specified position.
Link copied to clipboard
open fun instantiateItem(@NonNull container: ViewGroup, position: Int): Any
Link copied to clipboard
open fun isViewFromObject(@NonNull view: View, @NonNull object: Any): Boolean
Link copied to clipboard
open fun restoreState(@Nullable state: Parcelable, @Nullable loader: ClassLoader)
Link copied to clipboard
Link copied to clipboard
open fun setPrimaryItem(@NonNull container: ViewGroup, position: Int, @NonNull object: Any)
Link copied to clipboard
open fun startUpdate(@NonNull container: ViewGroup)